package com.tskj.leonsu.controller;

import com.alibaba.fastjson.JSONObject;
import com.tskj.leonsu.db.redis.util.RedisUtil;
import com.tskj.leonsu.service.LoginService;
import com.tskj.leonsu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private LoginService loginService;

    @Autowired
    private OrderService orderService;

    @GetMapping("/list")
    @ResponseBody
    public JSONObject getOrderList(@RequestParam String token, @RequestParam int type) {
        String adUserName = loginService.getAdUserName(token);
        JSONObject ret = new JSONObject();
        ret.put("code", 0);
        ret.put("data", orderService.getOrderList(adUserName, type));
        return ret;
    }

    @PostMapping("/confirm")
    @ResponseBody
    public JSONObject confirmOrder(@RequestParam String token, @RequestBody JSONObject data) {
        String adUserName = loginService.getAdUserName(token);
        return orderService.confirmOrder(adUserName, data, 1);
    }

    @PostMapping("/cancel")
    @ResponseBody
    public JSONObject cancelOrder(@RequestParam String token, @RequestBody JSONObject data) {
        String adUserName = loginService.getAdUserName(token);
        return orderService.confirmOrder(adUserName, data, 0);
    }
}
